package com.gitee.feizns.explore.data_structure.array_and_string.reverse;

/**
 * @author feizns
 * @since 2019/10/25
 */
public class ReverseInt {

    public static void main(String[] args) {

    }

    public static int reverse(int x) {
        StringBuilder val = new StringBuilder(String.valueOf(Math.abs(x)));
        return x < 0
                ? -reverse(val)
                : reverse(val);
    }

    private static int reverse(StringBuilder val) {
        try {
            return Integer.valueOf(val.reverse().toString());
        } catch(Exception e) {
            return 0;
        }
    }

}
